<template>
    <table border="1">
        <tr>
            <td>房型</td>
            <td>
                <select v-model="info.R_id">
                    <option :value="0">请选择</option>
                    <option v-for="i in xialainfo" :value="i.R_ID">{{ i.R_Name }}</option>
            </select>

            </td>
        </tr>
        <tr>
            <td>房号</td>
            <td>
                <select v-model="info.RN_id">
                    <option :value="0">请选择</option>
                    <option v-for="i in xialanumber" :value="i.RN_Id">{{ i.RN_Num }}</option>
            </select>

            </td>
        </tr>
        <tr>
            <td></td>
            <td>
                <input type="button" value="添加" @click="save">
            </td>
        </tr>
    </table>
</template>

<script setup lang="ts">
import {onMounted,ref} from 'vue'
import { useRoute,useRouter } from 'vue-router';
import axios from 'axios'

import {useCounterStore} from '../../stores/counter.ts'

const userstore=useCounterStore();

const user=useRouter();

const names=ref("")

//判断当前用户是否为管理员
const guanli=()=>{
  
  axios.get("https://localhost:7234/api/RoomInfo/GettypeByname",{
      params:{
          name:userstore.username
      }
  })
  .then(res=>{
      names.value=res.data
  })
}
const xialanumber=ref([{
    "RN_Id": 1,
    "RN_Num": "1002",
}])
const xialainfo=ref([{
    "R_ID": 1,
    "R_Name": "大床房",
}])
const info=ref({

  "RN_id": 0,
  "R_id": 0,
})
onMounted(()=>{
    xialanumbers()
    xialainfos()
    guanli()
})
const xialanumbers=()=>{
    axios.get("https://localhost:7234/api/RoomInfoNumber/GetXiaLaNumber")
    .then(res=>{
        xialanumber.value=res.data
    })
}
const xialainfos=()=>{
    axios.get("https://localhost:7234/api/RoomNumber/GetXilaInfo")
    .then(res=>{
        xialainfo.value=res.data
    })
}
const save=()=>{
    if(names.value!="管理员"){
        alert("对不起您无权限执行此操作");
        user.push("/Login")
        return;
    }
    if(confirm("您选择好了吗")){
        axios.post("https://localhost:7234/api/RoomInfoNumber/AddInfoNumber",info.value)
    .then(res=>{
        if(res.data>0){
            alert("添加成功");
        }else{
            alert("添加失败")
        }
    })
    }
 
}


</script>

<style scoped>

</style>